package com.shop2cn.iapi.agentproducts.testcase;

import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.SetVisibleBean;
import com.shop2cn.iapi.agentproducts.service.SetVisibleCall;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.ProductQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置商品是否露出Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetVisible{
	private static SetVisibleBean setvisibleBean;
	private static SetVisibleCall setvisibleCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置商品是否露出Test");
	}

	@Before
	public void caseUp() {
		setvisibleBean=new SetVisibleBean();
		setvisibleCall=new SetVisibleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setvisibleCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetVisible_001() {
		Logger.start(true,"设置露出不露出，查询数据库验证");
		try {
			Integer sellerId = GodmchManageCallService.CreateGodMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			setvisibleBean.setProductIds(Arrays.asList(productId));
			setvisibleBean.setUserId(sellerId);
			setvisibleBean.setVisible(false);
			setvisibleCall.setData(setvisibleBean);
			setvisibleCall.callService();
			Logger.verifyEquals("200", setvisibleCall.getString("code"), "验证code");
			Thread.sleep(3000);
			
			AgentProductPo selectAgentProductByProductId = new YmtProductsIWapper().selectAgentProductByProductId(productId);
			Logger.verifyEquals(true, selectAgentProductByProductId.isInvisible(), "验证是否露出");
			setvisibleBean.setVisible(true);
			setvisibleCall.setData(setvisibleBean);
			setvisibleCall.callService();			
			Logger.verifyEquals("200", setvisibleCall.getString("code"), "验证code");
			Thread.sleep(3000);
			selectAgentProductByProductId = new YmtProductsIWapper().selectAgentProductByProductId(productId);
			Logger.verifyEquals(false, selectAgentProductByProductId.isInvisible(), "验证是否露出");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}